package com.shop2cn.iapi.sqpayment.testcase;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.CharSet;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.sqpayment.parameter.AcquireOrderBean;
import com.shop2cn.iapi.sqpayment.parameter.DownloadBillBean;
import com.shop2cn.iapi.sqpayment.service.DownloadBillCall;
import com.ymatou.mq.admin.parameter.MessageListBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.MqQueryCallService;
import com.ymttest.business.service.SQPayGateWayCallService;
import com.ymttest.database.model.MPayment;
import com.ymttest.database.model.MRefund;
import com.ymttest.database.model.PPPayment;
import com.ymttest.database.model.PaymentCheck;
import com.ymttest.database.model.PaymentCheckDetail;
import com.ymttest.database.sqlwapper.SQPayGateWayWapper;
import com.ymttest.utils.RemoteShellExecutor2;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.ZipUtils;
/**
*下载mock对账单
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DownloadBill{
	private static DownloadBillBean downloadbillBean;
	private static DownloadBillCall downloadbillCall;
	SQPayGateWayWapper SQPayGateWayWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("下载mock对账单");
	}

	@Before
	public void caseUp() {
		downloadbillBean=new DownloadBillBean();
		//这里的对账单现在默认给6000 hipopay对账 后续可能会变更
		downloadbillCall=new DownloadBillCall("6000");
		SQPayGateWayWapper=new SQPayGateWayWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(downloadbillCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	/**生成对账信息明细HIPOPAY
	 * @param payTime
	 * @param instPaymentId
	 * @param incomeAmount
	 * @param payAmount
	 * @param settleCurrency
	 * @param feeAmount
	 * @return
	 */
	private String buildBillItem(Date payTime, String instPaymentId,String paymentid, BigDecimal incomeAmount, BigDecimal payAmount, String settleCurrency, BigDecimal feeAmount){
        return String.format("微信支付收款,%s,`%s,`%s,%s USD,-,1.13 USD,%s CNY,%s,%s HKD,-,-,-,-,-,-"
            , new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(payTime)
            , instPaymentId,paymentid, incomeAmount.setScale(2).toString(), payAmount.setScale(2).toString(), settleCurrency, feeAmount.setScale(2).toString());
    }
	
	/**
	 * 生成对账信息HIPOPAY
	 * @param payment
	 * @return
	 */
	private String getMockData(MPayment payment) {
		String r=BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()), 10, BigDecimal.ROUND_DOWN).toString();
		BigDecimal settleRate = new BigDecimal(r);
		BigDecimal settleAmount = settleRate.multiply(payment.getOrderAmt()) // 算出外部金额
                .setScale(2, BigDecimal.ROUND_DOWN);        // 取两位小数 尾部截断
		String data="洋码头 20190305至20190305 Mock对账单\r\n" +
                "业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道\r\n" +
                buildBillItem(payment.getPayTime(), payment.getInstitutionPaymentId(),payment.getPaymentId(), settleAmount, payment.getOrderAmt(),r, BigDecimal.ZERO);
		return data;
	}
	private String getMockData(MPayment payment,BigDecimal errorValue) {
		String r=BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()), 10, BigDecimal.ROUND_DOWN).toString();
		BigDecimal settleRate = new BigDecimal(r);
		BigDecimal settleAmount = settleRate.multiply(payment.getOrderAmt()) // 算出外部金额
                .setScale(2, BigDecimal.ROUND_DOWN);        // 取两位小数 尾部截断
		String data="洋码头 20190305至20190305 Mock对账单\r\n" +
                "业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道\r\n" +
                buildBillItem(payment.getPayTime(), payment.getInstitutionPaymentId(),payment.getPaymentId(),payment.getOrderAmt(), settleAmount.add(errorValue).setScale(2,BigDecimal.ROUND_DOWN), r, BigDecimal.ZERO);
		return data;
	}
	private String getFQLCheckFile(List<MPayment> pms ) throws IOException {
		String filename=TestDataManager.getRandomUUID().toString()+".csv";
		String path="temp"+File.separator+filename;
		List<String> lines=new ArrayList<String>();
		String head="\"结算平台\",\"订单号\",\"第三方订单号\",\"订单状态\",\"订单类型\",\"结算状态\",\"商品ID\",\"商品售价\",\"订单金额\",\"结算金额(-表示冲销)\",\"扣点\",\"订单创建时间\",\"分期乐优惠\",\"渠道变价幅度(+表示提价/-表示降价)\",\"订单佣金\",\"拉新佣金\",\"分摊平台优惠券\",\"优惠券\",\"拼单活动\",\"单品促销\",\"赠品促销\",\"满减促销\",\"会员促销\",\"满折促销\",\"加价购促销\",\"套餐促销\",\"N元任选促销\",\"购物金\",\"礼品卡\",\"商品名称\",\"商品规格\",\"一级类目\",\"二级类目\",\"三级类目\",\"品牌\",\"第三方流水号\",\"是否周期内冲销\",\"备注\"";
		lines.add(head);
		pms.forEach(pm->{
			String line1="\"分期乐\",\""+pm.getInstitutionPaymentId()+"\",\""+pm.getPaymentId()+"\",\"已完成\",\"普通订单\",\"成功\",\"MES201812242688555\",\"1959\",\"1959\",\""+pm.getOrderAmt().setScale(2)+"\",\"0.00%\",\""+YMTDateUtil.getBeforeOrNextDay(0, "yyyy-MM-dd HH:mm:ss")+"\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"\",\"\",\"乐卡分期支付\",\"乐卡分期支付\",\"乐卡分期支付\",\"乐卡分期lekapay\",\"'\",\"否\",\"\"";
			lines.add(line1);
		});
		TestDataManager.writeToFile(path, lines,StandardCharsets.US_ASCII);
		return path;
	}
	private String getSFTCheckFile(List<MPayment> pms ) throws IOException {
		String filename=YMTDateUtil.getBeforeOrNextDay(-1, "yyyy-MM-dd")+"_账务明细.csv";
		String path="temp"+File.separator+filename;
		List<String> lines=new ArrayList<String>();
		String head="结算时间, 支付时间, 商户订单号, 产品订单号, 订单金额(元), 入账金额(元), 出账金额(元), 手续费支出(元), 手续费退还(元), 业务类型, 交易渠道,收款姓名, 收款卡号, 备注1, 备注2";
		lines.add(head);
		pms.forEach(pm->{
			String time=YMTDateUtil.getBeforeOrNextDay(0);
			String line1="	"+time+",	"+time+",	"+pm.getPaymentId()+",	"+pm.getInstitutionPaymentId()+","+pm.getOrderAmt()+","+pm.getOrderAmt()+",0.00,-1.02,0.00,线上收单,微信公众号,,,组合支付结算,null";
			lines.add(line1);
		});
		TestDataManager.writeToFile(path, lines,StandardCharsets.UTF_8);
		return path;
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_001() {
		Logger.start(true,"6000对账文件下载成功");
		try {
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6000");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			String fname="HipoPay自动对账_wxsqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.verifyEquals(BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()),10, BigDecimal.ROUND_DOWN), new BigDecimal(cdinfo.get(0).getCsvExchaneRate()).setScale(10), "验证汇率");
			Logger.verifyEquals(payment.getSettleAmount(), cdinfo.get(0).getCsvSettleAmount(), "验证SettleAmount");
			//币种跟着服务费币种
			Logger.verifyEquals("HKD", cdinfo.get(0).getCsvSettleCurrency(), "验证CsvSettleCurrency");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证CsvPaymentId");
			// 验证总线消息 Message message = new Message("payment", "settle_notify", paymentPo.getPaymentId(), paymentSettleNotifyReq);
			MessageListBean MessageListBean = MqQueryCallService.initGodCheckPaymentDetail(payment.getPaymentId());
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Map ele=joa.get(0);
			Logger.verifyEquals(payment.getInstitutionPaymentId(), ele.get("instPaymentId"), "instPaymentId");
			Logger.verifyEquals(payment.getOrderAmt(), new BigDecimal( ele.get("orderAmount").toString()).setScale(2), "orderAmount");
			Logger.verifyEquals(payment.getPaymentId(), ele.get("paymentId"), "paymentId");
			Logger.verifyEquals(payment.getSettleAmount(),new BigDecimal( ele.get("settleAmount").toString()).setScale(2), "settleAmount");
			Logger.verifyEquals(payment.getSettleCurrency(), ele.get("settleCurrency"), "settleCurrency");
			Logger.verifyEquals(payment.getTradingId(), ele.get("tradingId"), "tradingId");
			//{"instPaymentId":"65df1b523f1c4162a2117db1c768da7","orderAmount":5,"paymentId":"19031915282187760","settleAmount":4.27,"settleCurrency":"HKD","tradingId":"1196642122787777"}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_DownloadBill_002() {
		//201908 分期乐会返回多个文件所以需要按照Tc_DownloadBill_004 来处理 这里的当文件会失败  目前忽略这个case
		Logger.start(true,"90对账文件下载成功");
		try {
			downloadbillCall=new DownloadBillCall("90");
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("90");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getCheckStatus(), "验证getCheckStatus");
			String file=getFQLCheckFile(Arrays.asList(payment));
			String zipfile=file.substring(0,file.lastIndexOf("csv"))+"zip";
			ZipUtils.zipFiles(file, zipfile);
			String furl=TestDataManager.UploadFile(zipfile);
			
//			AcquireOrderBean aqb2 = SQPayGateWayCallService.initAcquireOrder("90");
//			SQPayGateWayCallService.acquireOrder(aqb2);
//			SQPayGateWayCallService.notifyCall(aqb2);
//			MPayment payment2 = SQPayGateWayWapper.selectPaymentByTradingid(aqb2.getOrderId()).get(0);
//			Logger.verifyEquals(0, payment2.getCheckStatus(), "验证getCheckStatus");
//			String file2=getFQLCheckFile(Arrays.asList(payment2));
//			String zipfile2=file2.substring(0,file2.lastIndexOf("csv"))+"zip";
//			ZipUtils.zipFiles(file2, zipfile2);
//			String furl2=TestDataManager.UploadFile(zipfile2);
			
			
			downloadbillBean.setMockData(furl);
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			//分期乐自动对账_2019-06-28_133952f7-84fb-451f-b71d-d7d0c0ea84da
			String fname="分期乐自动对账_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
			Logger.debug("PaymentCheck:"+FormatUtil.beanToGSONString(check));
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.debug("PaymentCheckDetail:"+FormatUtil.beanToGSONString(cdinfo));
			Logger.verifyEquals(payment.getOrderAmt().setScale(2), cdinfo.get(0).getCsvAmount().setScale(2), "验证amt");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证getCsvPaymentId");
			Logger.verifyEquals(payment.getInstitutionPaymentId(), cdinfo.get(0).getInstPaymentId(), "验证getInstPaymentId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_003() {
		Logger.start(true,"6001对账文件下载成功");
		try {
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6001");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			//HipoPay自动对账_wxsqBuyer_2019-07-22_b97d2938-0a3f-4d8f-82fb-17d4fdf7496a
			String fname="HipoPay自动对账_wxsqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck("6000", fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			Logger.debug("数据："+check.get(0).getId()+payment.getInstitutionPaymentId());
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.verifyEquals(BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()),10, BigDecimal.ROUND_DOWN), new BigDecimal(cdinfo.get(0).getCsvExchaneRate()).setScale(10), "验证汇率");
			Logger.verifyEquals(payment.getSettleAmount(), cdinfo.get(0).getCsvSettleAmount(), "验证SettleAmount");
			//币种跟着服务费币种
			Logger.verifyEquals("HKD", cdinfo.get(0).getCsvSettleCurrency(), "验证CsvSettleCurrency");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证CsvPaymentId");
			// 验证总线消息 Message message = new Message("payment", "settle_notify", paymentPo.getPaymentId(), paymentSettleNotifyReq);
			MessageListBean MessageListBean = MqQueryCallService.initGodCheckPaymentDetail(payment.getPaymentId());
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Map ele=joa.get(0);
			Logger.verifyEquals(payment.getInstitutionPaymentId(), ele.get("instPaymentId"), "instPaymentId");
			Logger.verifyEquals(payment.getOrderAmt(), new BigDecimal( ele.get("orderAmount").toString()).setScale(2), "orderAmount");
			Logger.verifyEquals(payment.getPaymentId(), ele.get("paymentId"), "paymentId");
			Logger.verifyEquals(payment.getSettleAmount(),new BigDecimal( ele.get("settleAmount").toString()).setScale(2), "settleAmount");
			Logger.verifyEquals(payment.getSettleCurrency(), ele.get("settleCurrency"), "settleCurrency");
			Logger.verifyEquals(payment.getTradingId(), ele.get("tradingId"), "tradingId");
			//{"instPaymentId":"65df1b523f1c4162a2117db1c768da7","orderAmount":5,"paymentId":"19031915282187760","settleAmount":4.27,"settleCurrency":"HKD","tradingId":"1196642122787777"}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_004() {
		Logger.start(true,"90对账文件下载成功-2个文件");
		try {
			downloadbillCall=new DownloadBillCall("90");
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("90");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getCheckStatus(), "验证getCheckStatus");
			String file=getFQLCheckFile(Arrays.asList(payment));
			String zipfile=file.substring(0,file.lastIndexOf("csv"))+"zip";
			ZipUtils.zipFiles(file, zipfile);
			String furl=TestDataManager.UploadFile(zipfile);
			
			AcquireOrderBean aqb2 = SQPayGateWayCallService.initAcquireOrder("90");
			SQPayGateWayCallService.acquireOrder(aqb2);
			SQPayGateWayCallService.notifyCall(aqb2);
			MPayment payment2 = SQPayGateWayWapper.selectPaymentByTradingid(aqb2.getOrderId()).get(0);
			Logger.verifyEquals(0, payment2.getCheckStatus(), "验证getCheckStatus");
			String file2=getFQLCheckFile(Arrays.asList(payment2));
			String zipfile2=file2.substring(0,file2.lastIndexOf("csv"))+"zip";
			ZipUtils.zipFiles(file2, zipfile2);
			String furl2=TestDataManager.UploadFile(zipfile2);
			
			
			downloadbillBean.setMockData(furl+","+furl2);
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			//分期乐自动对账_2019-06-28_133952f7-84fb-451f-b71d-d7d0c0ea84da
			String fname="分期乐自动对账_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.debug(FormatUtil.beanToGSONString(cdinfo));
			Logger.verifyEquals(payment.getOrderAmt().setScale(2), cdinfo.get(0).getCsvAmount().setScale(2), "验证amt");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证getCsvPaymentId");
			Logger.verifyEquals(payment.getInstitutionPaymentId(), cdinfo.get(0).getInstPaymentId(), "验证getInstPaymentId");
			
			
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb2.getOrderId()).get(0);
			//分期乐自动对账_2019-06-28_133952f7-84fb-451f-b71d-d7d0c0ea84da
			fname="分期乐自动对账_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.debug(FormatUtil.beanToGSONString(cdinfo));
			Logger.verifyEquals(payment.getOrderAmt().setScale(2), cdinfo.get(0).getCsvAmount().setScale(2), "验证amt");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证getCsvPaymentId");
			Logger.verifyEquals(payment.getInstitutionPaymentId(), cdinfo.get(0).getInstPaymentId(), "验证getInstPaymentId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_005() {
		Logger.start(true,"6002对账文件下载成功");
		try {
			downloadbillCall=new DownloadBillCall("6002");
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6002");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			//HipoPay自动对账_wxsqBuyer_2019-07-22_b97d2938-0a3f-4d8f-82fb-17d4fdf7496a
			String fname="HipoPayH5New自动对账_h5sqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck("6002", fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			Logger.debug("数据："+check.get(0).getId()+payment.getInstitutionPaymentId());
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.verifyEquals(BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()),10, BigDecimal.ROUND_DOWN), new BigDecimal(cdinfo.get(0).getCsvExchaneRate()).setScale(10), "验证汇率");
			Logger.verifyEquals(payment.getSettleAmount(), cdinfo.get(0).getCsvSettleAmount(), "验证SettleAmount");
			//币种跟着服务费币种
			Logger.verifyEquals("HKD", cdinfo.get(0).getCsvSettleCurrency(), "验证CsvSettleCurrency");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证CsvPaymentId");
			// 验证总线消息 Message message = new Message("payment", "settle_notify", paymentPo.getPaymentId(), paymentSettleNotifyReq);
			MessageListBean MessageListBean = MqQueryCallService.initGodCheckPaymentDetail(payment.getPaymentId());
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Map ele=joa.get(0);
			Logger.verifyEquals(payment.getInstitutionPaymentId(), ele.get("instPaymentId"), "instPaymentId");
			Logger.verifyEquals(payment.getOrderAmt(), new BigDecimal( ele.get("orderAmount").toString()).setScale(2), "orderAmount");
			Logger.verifyEquals(payment.getPaymentId(), ele.get("paymentId"), "paymentId");
			Logger.verifyEquals(payment.getSettleAmount(),new BigDecimal( ele.get("settleAmount").toString()).setScale(2), "settleAmount");
			Logger.verifyEquals(payment.getSettleCurrency(), ele.get("settleCurrency"), "settleCurrency");
			Logger.verifyEquals(payment.getTradingId(), ele.get("tradingId"), "tradingId");
			//{"instPaymentId":"65df1b523f1c4162a2117db1c768da7","orderAmount":5,"paymentId":"19031915282187760","settleAmount":4.27,"settleCurrency":"HKD","tradingId":"1196642122787777"}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	//待确认 下载方式变更 对账文件变更
	public void Tc_DownloadBill_006() {
		Logger.start(true,"6010对账文件下载成功");
		try {
			downloadbillCall=new DownloadBillCall("6010");
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6010");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getCheckStatus(), "验证getCheckStatus");
			
			String file=getSFTCheckFile(Arrays.asList(payment));
			//20191145_对账单.zip
			String zipfile="temp"+File.separator+YMTDateUtil.getBeforeOrNextDay(-1, "yyyyMMdd")+"_对账单.zip";
			ZipUtils.zipFiles(file, zipfile);
			
			RemoteShellExecutor2 rse = new RemoteShellExecutor2("172.16.101.106", "ftpuser", "1qaz@WSX");
			rse.login();
			rse.transferFile(zipfile, "/SIT1/sftcheckfile/");
			
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			//ShengPayWxAPP自动对账_2019-12-06_331e3892-77c2-4a97-97cf-e0c10c86eb56
			String fname="ShengPayWxAPP自动对账_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.debug(FormatUtil.beanToGSONString(cdinfo));
//			Logger.verifyEquals(payment.getOrderAmt().setScale(2), cdinfo.get(0).getCsvAmount().setScale(2), "验证amt");
//			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证getCsvPaymentId");
//			Logger.verifyEquals(payment.getInstitutionPaymentId(), cdinfo.get(0).getInstPaymentId(), "验证getInstPaymentId");
//			
//			
//			fname="分期乐自动对账_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
//			check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
//			Logger.verifyEquals(1, check.size(), "验证数据");
//			cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
//			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
//			Logger.debug(FormatUtil.beanToGSONString(cdinfo));
//			Logger.verifyEquals(payment.getOrderAmt().setScale(2), cdinfo.get(0).getCsvAmount().setScale(2), "验证amt");
//			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证getCsvPaymentId");
//			Logger.verifyEquals(payment.getInstitutionPaymentId(), cdinfo.get(0).getInstPaymentId(), "验证getInstPaymentId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_007() {
		Logger.start(true,"6103对账文件下载成功");
		try {
			downloadbillCall=new DownloadBillCall("6000");
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6103");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			String fname="HipoPay自动对账_wxsqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck("6000", fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.verifyEquals(BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()),10, BigDecimal.ROUND_DOWN), new BigDecimal(cdinfo.get(0).getCsvExchaneRate()).setScale(10), "验证汇率");
			Logger.verifyEquals(payment.getSettleAmount(), cdinfo.get(0).getCsvSettleAmount(), "验证SettleAmount");
			//币种跟着服务费币种
			Logger.verifyEquals("HKD", cdinfo.get(0).getCsvSettleCurrency(), "验证CsvSettleCurrency");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证CsvPaymentId");
			// 验证总线消息 Message message = new Message("payment", "settle_notify", paymentPo.getPaymentId(), paymentSettleNotifyReq);
			MessageListBean MessageListBean = MqQueryCallService.initGodCheckPaymentDetail(payment.getPaymentId());
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Map ele=joa.get(0);
			Logger.verifyEquals(payment.getInstitutionPaymentId(), ele.get("instPaymentId"), "instPaymentId");
			Logger.verifyEquals(payment.getOrderAmt(), new BigDecimal( ele.get("orderAmount").toString()).setScale(2), "orderAmount");
			Logger.verifyEquals(payment.getPaymentId(), ele.get("paymentId"), "paymentId");
			Logger.verifyEquals(payment.getSettleAmount(),new BigDecimal( ele.get("settleAmount").toString()).setScale(2), "settleAmount");
			Logger.verifyEquals(payment.getSettleCurrency(), ele.get("settleCurrency"), "settleCurrency");
			Logger.verifyEquals(payment.getTradingId(), ele.get("tradingId"), "tradingId");
			//{"instPaymentId":"65df1b523f1c4162a2117db1c768da7","orderAmount":5,"paymentId":"19031915282187760","settleAmount":4.27,"settleCurrency":"HKD","tradingId":"1196642122787777"}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_008() {
		Logger.start(true,"6107对账文件下载成功");
		try {
			downloadbillCall=new DownloadBillCall("6000");
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6107");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			String fname="HipoPay自动对账_wxsqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck("6000", fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.verifyEquals(BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()),10, BigDecimal.ROUND_DOWN), new BigDecimal(cdinfo.get(0).getCsvExchaneRate()).setScale(10), "验证汇率");
			Logger.verifyEquals(payment.getSettleAmount(), cdinfo.get(0).getCsvSettleAmount(), "验证SettleAmount");
			//币种跟着服务费币种
			Logger.verifyEquals("HKD", cdinfo.get(0).getCsvSettleCurrency(), "验证CsvSettleCurrency");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证CsvPaymentId");
			// 验证总线消息 Message message = new Message("payment", "settle_notify", paymentPo.getPaymentId(), paymentSettleNotifyReq);
			MessageListBean MessageListBean = MqQueryCallService.initGodCheckPaymentDetail(payment.getPaymentId());
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Map ele=joa.get(0);
			Logger.verifyEquals(payment.getInstitutionPaymentId(), ele.get("instPaymentId"), "instPaymentId");
			Logger.verifyEquals(payment.getOrderAmt(), new BigDecimal( ele.get("orderAmount").toString()).setScale(2), "orderAmount");
			Logger.verifyEquals(payment.getPaymentId(), ele.get("paymentId"), "paymentId");
			Logger.verifyEquals(payment.getSettleAmount(),new BigDecimal( ele.get("settleAmount").toString()).setScale(2), "settleAmount");
			Logger.verifyEquals(payment.getSettleCurrency(), ele.get("settleCurrency"), "settleCurrency");
			Logger.verifyEquals(payment.getTradingId(), ele.get("tradingId"), "tradingId");
			//{"instPaymentId":"65df1b523f1c4162a2117db1c768da7","orderAmount":5,"paymentId":"19031915282187760","settleAmount":4.27,"settleCurrency":"HKD","tradingId":"1196642122787777"}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_009() {
		Logger.start(true,"6003对账文件下载成功");
		try {
			downloadbillCall=new DownloadBillCall("6003");
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6003");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			//HipoPay自动对账_wxsqBuyer_2019-07-22_b97d2938-0a3f-4d8f-82fb-17d4fdf7496a
			String fname="HIPOPAY_H5_MY自动对账_h5sqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck("6003", fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			Logger.debug("数据："+check.get(0).getId()+payment.getInstitutionPaymentId());
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.verifyEquals(BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()),10, BigDecimal.ROUND_DOWN), new BigDecimal(cdinfo.get(0).getCsvExchaneRate()).setScale(10), "验证汇率");
			Logger.verifyEquals(payment.getSettleAmount(), cdinfo.get(0).getCsvSettleAmount(), "验证SettleAmount");
			//币种跟着服务费币种
			Logger.verifyEquals("HKD", cdinfo.get(0).getCsvSettleCurrency(), "验证CsvSettleCurrency");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证CsvPaymentId");
			// 验证总线消息 Message message = new Message("payment", "settle_notify", paymentPo.getPaymentId(), paymentSettleNotifyReq);
			MessageListBean MessageListBean = MqQueryCallService.initGodCheckPaymentDetail(payment.getPaymentId());
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Map ele=joa.get(0);
			Logger.verifyEquals(payment.getInstitutionPaymentId(), ele.get("instPaymentId"), "instPaymentId");
			Logger.verifyEquals(payment.getOrderAmt(), new BigDecimal( ele.get("orderAmount").toString()).setScale(2), "orderAmount");
			Logger.verifyEquals(payment.getPaymentId(), ele.get("paymentId"), "paymentId");
			Logger.verifyEquals(payment.getSettleAmount(),new BigDecimal( ele.get("settleAmount").toString()).setScale(2), "settleAmount");
			Logger.verifyEquals(payment.getSettleCurrency(), ele.get("settleCurrency"), "settleCurrency");
			Logger.verifyEquals(payment.getTradingId(), ele.get("tradingId"), "tradingId");
			//{"instPaymentId":"65df1b523f1c4162a2117db1c768da7","orderAmount":5,"paymentId":"19031915282187760","settleAmount":4.27,"settleCurrency":"HKD","tradingId":"1196642122787777"}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_010() {
		Logger.start(true,"6000对账文件下载成功-可以有0.01误差");
		try {
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			BigDecimal errorValue=new BigDecimal(0.01);
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6000");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment,errorValue);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			String fname="HipoPay自动对账_wxsqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");
			Logger.verifyEquals(BigDecimal.ONE.divide(new BigDecimal( payment.getSettleRate()),10, BigDecimal.ROUND_DOWN), new BigDecimal(cdinfo.get(0).getCsvExchaneRate()).setScale(10), "验证汇率");
			Logger.verifyEquals(payment.getSettleAmount().add(errorValue).setScale(2,BigDecimal.ROUND_DOWN), cdinfo.get(0).getCsvSettleAmount(), "验证SettleAmount");
			//币种跟着服务费币种
			Logger.verifyEquals("HKD", cdinfo.get(0).getCsvSettleCurrency(), "验证CsvSettleCurrency");
			Logger.verifyEquals(payment.getPaymentId(), cdinfo.get(0).getCsvPaymentId(), "验证CsvPaymentId");
			// 验证总线消息 Message message = new Message("payment", "settle_notify", paymentPo.getPaymentId(), paymentSettleNotifyReq);
			MessageListBean MessageListBean = MqQueryCallService.initGodCheckPaymentDetail(payment.getPaymentId());
			List <Map> joa = MqQueryCallService.GetMqMessage(MessageListBean);
			if(joa.size()==0){
				Thread.sleep(5000);
				 joa = MqQueryCallService.GetMqMessage(MessageListBean);
			}
			Map ele=joa.get(0);
			Logger.verifyEquals(payment.getInstitutionPaymentId(), ele.get("instPaymentId"), "instPaymentId");
			Logger.verifyEquals(payment.getOrderAmt(), new BigDecimal( ele.get("orderAmount").toString()).setScale(2), "orderAmount");
			Logger.verifyEquals(payment.getPaymentId(), ele.get("paymentId"), "paymentId");
			Logger.verifyEquals(payment.getSettleAmount().add(errorValue).setScale(2,BigDecimal.ROUND_DOWN),new BigDecimal( ele.get("settleAmount").toString()).setScale(2), "settleAmount");
			Logger.verifyEquals(payment.getSettleCurrency(), ele.get("settleCurrency"), "settleCurrency");
			Logger.verifyEquals(payment.getTradingId(), ele.get("tradingId"), "tradingId");
			//{"instPaymentId":"65df1b523f1c4162a2117db1c768da7","orderAmount":5,"paymentId":"19031915282187760","settleAmount":4.27,"settleCurrency":"HKD","tradingId":"1196642122787777"}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DownloadBill_011() {
		Logger.start(true,"6000对账文件下载成功-超过0.01误差失败");
		try {
//			业务类型,发生时间,单号,外部单号,入账,出账,余额,交易金额,结算汇率,服务费,退款金额,退款订单,外部退款单号,提现手续费,换汇币种,换汇汇率,换汇后金额,支付渠道
//			微信支付收款,2019-03-25 10:16:53,`2019032510165339739514322,`19032510165394010,0.00 USD,-,0.07 USD,0.10 CNY,0.148738695859114707,0.00 USD,-,-,-,-,-,-,-,WECHATPAYCN
			BigDecimal errorValue=new BigDecimal(0.02);
			AcquireOrderBean aqb = SQPayGateWayCallService.initAcquireOrder("6000");
			SQPayGateWayCallService.acquireOrder(aqb);
			SQPayGateWayCallService.notifyCall(aqb);
			MPayment payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, payment.getSettleStatus(), "验证SettleStatus");
			downloadbillBean.setDate(YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDTHMS_STRING));
			downloadbillBean.setFileCheckChannelEnum("HIPOPAY");
			String mock=getMockData(payment,errorValue);
			Logger.debug("mock:"+mock);
			downloadbillBean.setMockData(mock);
			downloadbillBean.setNo(TestDataManager.getRandomUUID().toString());
			downloadbillCall.setData(downloadbillBean);
			downloadbillCall.callService();			
			Logger.verifyEquals("ok", downloadbillCall.getReturnData(), "验证返回");
			Thread.sleep(5000);
			payment = SQPayGateWayWapper.selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, payment.getSettleStatus(), "验证SettleStatus");
			//HipoPay自动对账_2019-03-19_93dd87ff-0369-46d8-9ff0-73b30f8c2221
			String fname="HipoPay自动对账_wxsqBuyer_"+YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMD)+"_"+downloadbillBean.getNo();
			List<PaymentCheck> check = SQPayGateWayWapper.selectPaymentCheck(aqb.getPayType(), fname);
			Logger.verifyEquals(1, check.size(), "验证数据");
			List<PaymentCheckDetail> cdinfo = SQPayGateWayWapper.selectPaymentCheckDetail(check.get(0).getId(),payment.getInstitutionPaymentId());
			Logger.verifyEquals(1, cdinfo.size(), "验证数据");		
			} 
		catch (Exception e) {
			Logger.fail(e);
		}
	}
}